package br.com.engine.image;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ControleImagem 
{
	public static BufferedImage carregarSprite( String strPath )
	{
		BufferedImage image = null;
		
		try
		{
			image = ImageIO.read( new File( strPath ) );
		} 
		catch( IOException e ) 
		{
			e.printStackTrace( );
		}
		
		return image;
	}
	
	public static BufferedImage[] recortarImagem( BufferedImage image, int cx, int cy )
	{
		BufferedImage allImages[] = new BufferedImage[cx*cy];
		
		int width  = ( image.getWidth( )  / cx );
		int height = ( image.getHeight( ) / cy );
		
		int ncount = -1;
		
		for( int y = 0; y < image.getHeight( ); y = y + height )
		{
			for( int x = 0; x < image.getWidth( ); x = x + width )
			{
				allImages[++ncount] = image.getSubimage( x, y, width, height ); 
			}
		}
		
		return allImages;
	}
}